#include "UICreateFactory.h"

#include <WndBase.h>
#include <WndButton.h>
#include <WndEdit.h>
#include <WndLoadPicture.h>
#include <WndStatic.h>
#include <UIDefine.h>

#include <QString>
#include <QDir>
CUICreateFactory::CUICreateFactory(void)
{
}

CUICreateFactory::~CUICreateFactory(void)
{
}

CWndBase* CUICreateFactory::CreateUI( int nType, int nID, CWndBase* pParent, const char* pRes )
{
	CWndBase* pCreateWnd = NULL;
	switch ( nType )
	{
	case UI_CREATE_WNDBASE:
		{
			CWndBase* pWnd = new CWndBase;
			pWnd->Create(0,0,100,100,pParent,nID);
			pCreateWnd = pWnd;
		}
		break;
	case UI_CREATE_WNDBUTTON:
		{
			std::string strFile = _GetFilePath( pRes );
			CWndButton* pBtn = new CWndButton;
			pBtn->Create(0,0,0,0,strFile.c_str(),pParent,nID);
			pCreateWnd = pBtn;
		}
		break;
	case UI_CREATE_WNDSTATIC:
		{
			CWndStatic* pStatic = new CWndStatic;
			pStatic->CreateNoFont(100,0,100,14,pRes,pParent,nID);
			pCreateWnd = pStatic;
		}
		break;
	case UI_CREATE_WNDEDIT:
		{
			CWndEdit* pEdit = new CWndEdit;
			pEdit->CreateNoFont( 0, 0, 100, 14, pParent, nID );
			pCreateWnd = pEdit;
		}
		break;
	case UI_CREATE_WNDPICTURE:
		{
			std::string strFile = _GetFilePath( pRes );
			CWndLoadPicture* pPicture = new CWndLoadPicture;
			pPicture->Create(0,0,strFile.c_str(),pParent,nID,false,0,0,0,0);
			pCreateWnd = pPicture;
		}
		break;
	default:
		break;
	}
	return pCreateWnd;
}

std::string CUICreateFactory::_GetFilePath( const char* pChar )
{
	QString strQ = QDir::currentPath();
	QString strPath = pChar;

	QString strNew = "";

	int nDirPos = strPath.indexOf( strQ );
	nDirPos = strQ.length() + nDirPos;

	int nSizeNeed = strPath.length() - nDirPos - 1;
	strNew = strPath.right( nSizeNeed );

	std::string strNewStd = strNew.toStdString();
	return strNewStd;
}